package com.scc.servlet;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.scc.entites.dto.DishEntityDTO;
import com.scc.services.IDishSetupService;

@Controller
@RequestMapping(value = "/CreateDish")
public class CreateDish
{
   @Autowired
   IDishSetupService setupService;

   @RequestMapping(method = RequestMethod.GET)
   public String showForm(ModelMap model)
   {
      DishEntityDTO dish = new DishEntityDTO();
      model.addAttribute("DISH", dish);
      return "registration";
   }

   @RequestMapping(method = RequestMethod.POST)
   public String processForm(@ModelAttribute(value = "DISH")
   DishEntityDTO dish, BindingResult result)
   {
      setupService.createDish(dish);
      System.out.println("User values is : " + dish);
      return "success";
   }
}
